package com.ahsjdy.st.stbomanagerweb.controller;

import com.ahsjdy.st.stdao.entity.User;
import com.ahsjdy.st.stservice.service.UserService;
import com.ahsjdy.st.stservice.service.impl.NavServiceImpl;
import com.ahsjdy.stcommon.dto.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Description
 * @Author xuetao wang
 * @Date 2019/12/29
 */

@RestController
public class UserController extends BaseController {

    @Autowired
    private NavServiceImpl navService;

    @Autowired
    private UserService userService;

    @RequestMapping("/user/login")
    public ResponseDTO login(String username, String password, HttpSession session) {
        User user = userService.login(username, password);
        session.setAttribute("loginUser", user);
        return ResponseDTO.success();
    }


    @RequestMapping("/user/addNav")
    public ResponseDTO addNav(String navName, int level, Integer parentId, String price, String remark) {
        navService.addNav(navName, level, parentId, price, remark);
        return ResponseDTO.success();
    }

    @RequestMapping("/user/queryFirstNav")
    public ResponseDTO queryFirstNav() {
        return ResponseDTO.success(navService.listFirstNav());
    }

    @RequestMapping("/user/querySecondeNav")
    public ResponseDTO querySecondeNav(int parentId) {
        return ResponseDTO.success(navService.listSecondNav(parentId));
    }

    @RequestMapping("/user/modiyNav")
    public ResponseDTO modiyNav(Integer navId, String navName, String price, Integer status) {
        navService.modifyNav(navId, navName, price, status);
        return ResponseDTO.success();
    }
}
